layui.use('upload', function(){
    setPortrait();
    var $ = layui.jquery,upload = layui.upload;
    //普通图片上传
    var uploadInst = upload.render({
        elem: '#test1'
        ,url: '/uploadFile' //改成您自己的上传接口
        ,done: function(res){
            //如果上传失败
            if(res.code == 0){

                return $("#portrait").attr('src',res.data);
            }else {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var portrait = $('#portrait');
            portrait.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            portrait.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
            return
        }
    });
})


function setPortrait() {
    var user = localStorage.getItem('user');
    user = JSON.parse(user)
    $("#portrait").attr('src',user.ggLogo);
    $("#usernameInformation").append(user.ggNicheng)

    var ggPhone = user.ggPhone
    var ggPhone = ggPhone.split('')
    for (let i = 0; i < ggPhone.length; i++) {
        if (i === 3 | i === 4 | i === 5 | i === 6) {
            ggPhone[i] = '*'
        }

    }
    $("#phoneInformation").append(ggPhone)
    $("#youxiangInformation").append(user.ggYouxiang)
    $("#zhanghaoInformation").append(user.ggUsername)
}
function updataInformation(type) {
    var name = ''
    if(type == 1){
        name = '请输入修改的昵称!'
    }else if(type == 2){
        name = '请输入修改的密码!'
    }else if(type == 3){
        name = '请输入修改的绑定手机号!'
    }else if(type == 3){
        name = '请输入修改的绑定邮箱!'
    }
    //默认prompt
    layer.prompt({title: name,},function(val, index){

        // layer.msg('得到了'+val);
        // layer.close(index);
        console.log(val)

        $.ajax({
            type: 'GET',
            url: "/staff/userUpdatePersonal",
            dataType:"json",
            async: false,
            data:{
                type: type,
                content: val,
            },
            success: function (message) {
                if(message.code == 0){
                    layer.msg('修改成功，退出登陆后生效！');
                }else {
                    layer.msg(message.message);
                }
            }
        })
        layer.close(index);
    });
}